﻿using FluentNHibernate.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YYSite.Domain.System.UserPermissions;
using YYSite.Domain.System.IdentityUsers;
using YYSite.Domain.System.Permissions;
using YYSite.Domain.System.Positions;
using YYSite.Domain.System.Roles;
using YYSite.Domain.System;

namespace YYSite.Repository.System.UserPermissions
{
    public class UserPermissionMap : ClassMap<UserPermission>
    {
        public UserPermissionMap()
        {
            this.Table("UserPermission");
            this.Schema(SystemConstant.Schema);
            this.Id(p => p.Id);
            this.Map(p => p.UserId);
            this.Map(p => p.RoleId);
            this.Map(p => p.PositionId);
            this.Map(p => p.PermissionId);
            this.Map(p => p.HasGrant);
            this.Map(p => p.CreateTime).Not.Nullable().Default("GETDATE()");

            this.References<IdentityUser>(o => o.IdentityUser).Not.LazyLoad().Column("UserId");
            this.References<Role>(o => o.Role).Not.LazyLoad().Column("RoleId");
            this.References<Position>(o => o.Position).Not.LazyLoad().Column("PositionId");
            this.References<Permission>(o => o.Permission).Not.LazyLoad().Column("PermissionId");
        }
    }
}
